<?php

use console\db\Migration;

/**
 * 创建排查相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m190102_100003_t_staff extends Migration {

    /**
     * 居民信息表
     * @table `resident`
     */
    public function buildTableResident() {
        return [
            'comment' => '居民信息表',
            'columns' => [
                'id' => $this->primaryKey()->comment('居民ID'),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                'realname' => $this->string(50)->notNull()->comment('姓名'),
                'mobile' => $this->char(32)->comment('手机号'),
                'mobile_hash' => $this->char(255)->comment('加密手机号'),
                'idcardno' => $this->char(32)->unique()->comment('身份证号'),
                'idcardno_hash' => $this->char(255)->comment('加密身份证号'),
                'village_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('社区ID'),
                'family_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('家庭ID'),
                'address' => $this->string(255)->comment('联系地址'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('注册时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('注销时间'),
            ],
            'index' => [
                [
                    'columns' => 'user_id',
                ],
                [
                    'columns' => 'mobile',
                ],
                [
                    'columns' => 'village_id',
                ],
                [
                    'columns' => 'family_id',
                ],
                [
                    'columns' => 'realname',
                ]
            ]
        ];
    }

    /**
     * 社区信息表
     * @table `village`
     */
    public function buildTableVillage() {
        return [
            'comment' => '社区信息表',
            'columns' => [
                'id' => $this->primaryKey()->comment('ID'),
                'name' => $this->string(255)->notNull()->comment('社区名称'),
                'address' => $this->string(255)->comment('联系地址'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('注册时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('注销时间'),
            ],
            'index' => [
                [
                    'columns' => 'name',
                ]
            ]
        ];
    }

    /**
     * 家庭信息表
     * @table `family`
     */
    public function buildTableFamily() {
        return [
            'comment' => '家庭信息表',
            'columns' => [
                'id' => $this->primaryKey()->comment('ID'),
                'name' => $this->string(255)->notNull()->comment('家庭名称'),
                'address' => $this->string(255)->comment('联系地址'),
                'members' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('户籍人口数量'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('注册时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('注销时间'),
            ],
            'index' => [
                [
                    'columns' => 'name',
                ]
            ]
        ];
    }

}
